package me.helllp.book.concurrent.ch03;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 重入锁配合Condition
 * 
 * @author Administrator
 *
 */
public class ReenterLockCondition implements Runnable{
	public static ReentrantLock lock = new ReentrantLock();
	public static Condition condition = lock.newCondition();
	
	@Override
	public void run() {
		try {
			lock.lock();
			System.out.println("下一步：线程等待，同时释放锁");
			condition.await();
			System.out.println("线程在运行！！");
		} catch (InterruptedException e) {
			e.printStackTrace();
		}finally {
			lock.unlock();
		}
	}
	
	public static void main(String[] args) throws InterruptedException {
		ReenterLockCondition obj = new ReenterLockCondition();
		
		Thread t1 = new Thread(obj);
		t1.start();
		Thread.sleep(2000);
		
		lock.lock();
		condition.signal();
		lock.unlock();
	}
}
